home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2004 #2 / K-CD-2-2004.ISO / OpenOffice Sv / f_0397 / python-core-2.2.2 / lib / test / test_minidom.py < prev    next >
Encoding:
Python Source  |  2003-07-18  |  18.8 KB  |  650 lines

  1. # test for xml.dom.minidom
  2.  
  3. from xml.dom.minidom import parse, Node, Document, parseString
  4. from xml.dom import HierarchyRequestErr
  5. import xml.parsers.expat
  6.  
  7. import os
  8. import sys
  9. import traceback
  10. from test_support import verbose
  11.  
  12. if __name__ == "__main__":
  13.     base = sys.argv[0]
  14. else:
  15.     base = __file__
  16. tstfile = os.path.join(os.path.dirname(base), "test"+os.extsep+"xml")
  17. del base
  18.  
  19. def confirm(test, testname = "Test"):
  20.     if not test:
  21.         print "Failed " + testname
  22.         raise Exception
  23.  
  24. Node._debug = 1
  25.  
  26. def testParseFromFile():
  27.     from StringIO import StringIO
  28.     dom = parse(StringIO(open(tstfile).read()))
  29.     dom.unlink()
  30.     confirm(isinstance(dom,Document))
  31.  
  32. def testGetElementsByTagName():
  33.     dom = parse(tstfile)
  34.     confirm(dom.getElementsByTagName("LI") == \
  35.             dom.documentElement.getElementsByTagName("LI"))
  36.     dom.unlink()
  37.  
  38. def testInsertBefore():
  39.     dom = parseString("<doc><foo/></doc>")
  40.     root = dom.documentElement
  41.     elem = root.childNodes[0]
  42.     nelem = dom.createElement("element")
  43.     root.insertBefore(nelem, elem)
  44.     confirm(len(root.childNodes) == 2
  45.             and root.childNodes.length == 2
  46.             and root.childNodes[0] is nelem
  47.             and root.childNodes.item(0) is nelem
  48.             and root.childNodes[1] is elem
  49.             and root.childNodes.item(1) is elem
  50.             and root.firstChild is nelem
  51.             and root.lastChild is elem
  52.             and root.toxml() == "<doc><element/><foo/></doc>"
  53.             , "testInsertBefore -- node properly placed in tree")
  54.     nelem = dom.createElement("element")
  55.     root.insertBefore(nelem, None)
  56.     confirm(len(root.childNodes) == 3
  57.             and root.childNodes.length == 3
  58.             and root.childNodes[1] is elem
  59.             and root.childNodes.item(1) is elem
  60.             and root.childNodes[2] is nelem
  61.             and root.childNodes.item(2) is nelem
  62.             and root.lastChild is nelem
  63.             and nelem.previousSibling is elem
  64.             and root.toxml() == "<doc><element/><foo/><element/></doc>"
  65.             , "testInsertBefore -- node properly placed in tree")
  66.     nelem2 = dom.createElement("bar")
  67.     root.insertBefore(nelem2, nelem)
  68.     confirm(len(root.childNodes) == 4
  69.             and root.childNodes.length == 4
  70.             and root.childNodes[2] is nelem2
  71.             and root.childNodes.item(2) is nelem2
  72.             and root.childNodes[3] is nelem
  73.             and root.childNodes.item(3) is nelem
  74.             and nelem2.nextSibling is nelem
  75.             and nelem.previousSibling is nelem2
  76.             and root.toxml() == "<doc><element/><foo/><bar/><element/></doc>"
  77.             , "testInsertBefore -- node properly placed in tree")
  78.     dom.unlink()
  79.  
  80. def _create_fragment_test_nodes():
  81.     dom = parseString("<doc/>")
  82.     orig = dom.createTextNode("original")
  83.     c1 = dom.createTextNode("foo")
  84.     c2 = dom.createTextNode("bar")
  85.     c3 = dom.createTextNode("bat")
  86.     dom.documentElement.appendChild(orig)
  87.     frag = dom.createDocumentFragment()
  88.     frag.appendChild(c1)
  89.     frag.appendChild(c2)
  90.     frag.appendChild(c3)
  91.     return dom, orig, c1, c2, c3, frag
  92.  
  93. def testInsertBeforeFragment():
  94.     dom, orig, c1, c2, c3, frag = _create_fragment_test_nodes()
  95.     dom.documentElement.insertBefore(frag, None)
  96.     confirm(tuple(dom.documentElement.childNodes) == (orig, c1, c2, c3),
  97.             "insertBefore(<fragment>, None)")
  98.     frag.unlink()
  99.     dom.unlink()
  100.     #
  101.     dom, orig, c1, c2, c3, frag = _create_fragment_test_nodes()
  102.     dom.documentElement.insertBefore(frag, orig)
  103.     confirm(tuple(dom.documentElement.childNodes) == (c1, c2, c3, orig),
  104.             "insertBefore(<fragment>, orig)")
  105.     frag.unlink()
  106.     dom.unlink()
  107.  
  108. def testAppendChild():
  109.     dom = parse(tstfile)
  110.     dom.documentElement.appendChild(dom.createComment(u"Hello"))
  111.     confirm(dom.documentElement.childNodes[-1].nodeName == "#comment")
  112.     confirm(dom.documentElement.childNodes[-1].data == "Hello")
  113.     dom.unlink()
  114.  
  115. def testAppendChildFragment():
  116.     dom, orig, c1, c2, c3, frag = _create_fragment_test_nodes()
  117.     dom.documentElement.appendChild(frag)
  118.     confirm(tuple(dom.documentElement.childNodes) == (orig, c1, c2, c3),
  119.             "appendChild(<fragment>)")
  120.     frag.unlink()
  121.     dom.unlink()
  122.  
  123. def testReplaceChildFragment():
  124.     dom, orig, c1, c2, c3, frag = _create_fragment_test_nodes()
  125.     dom.documentElement.replaceChild(frag, orig)
  126.     orig.unlink()
  127.     confirm(tuple(dom.documentElement.childNodes) == (c1, c2, c3),
  128.             "replaceChild(<fragment>)")
  129.     frag.unlink()
  130.     dom.unlink()
  131.  
  132. def testLegalChildren():
  133.     dom = Document()
  134.     elem = dom.createElement('element')
  135.     text = dom.createTextNode('text')
  136.  
  137.     try: dom.appendChild(text)
  138.     except HierarchyRequestErr: pass
  139.     else:
  140.         print "dom.appendChild didn't raise HierarchyRequestErr"
  141.  
  142.     dom.appendChild(elem)
  143.     try: dom.insertBefore(text, elem)
  144.     except HierarchyRequestErr: pass
  145.     else:
  146.         print "dom.appendChild didn't raise HierarchyRequestErr"
  147.  
  148.     try: dom.replaceChild(text, elem)
  149.     except HierarchyRequestErr: pass
  150.     else:
  151.         print "dom.appendChild didn't raise HierarchyRequestErr"
  152.  
  153.     nodemap = elem.attributes
  154.     try: nodemap.setNamedItem(text)
  155.     except HierarchyRequestErr: pass
  156.     else:
  157.         print "NamedNodeMap.setNamedItem didn't raise HierarchyRequestErr"
  158.  
  159.     try: nodemap.setNamedItemNS(text)
  160.     except HierarchyRequestErr: pass
  161.     else:
  162.         print "NamedNodeMap.setNamedItemNS didn't raise HierarchyRequestErr"
  163.  
  164.     elem.appendChild(text)
  165.     dom.unlink()
  166.  
  167. def testNamedNodeMapSetItem():
  168.     dom = Document()
  169.     elem = dom.createElement('element')
  170.     attrs = elem.attributes
  171.     attrs["foo"] = "bar"
  172.     a = attrs.item(0)
  173.     confirm(a.ownerDocument is dom,
  174.             "NamedNodeMap.__setitem__() sets ownerDocument")
  175.     confirm(a.ownerElement is elem,
  176.             "NamedNodeMap.__setitem__() sets ownerElement")
  177.     confirm(a.value == "bar",
  178.             "NamedNodeMap.__setitem__() sets value")
  179.     confirm(a.nodeValue == "bar",
  180.             "NamedNodeMap.__setitem__() sets nodeValue")
  181.     elem.unlink()
  182.     dom.unlink()
  183.  
  184. def testNonZero():
  185.     dom = parse(tstfile)
  186.     confirm(dom)# should not be zero
  187.     dom.appendChild(dom.createComment("foo"))
  188.     confirm(not dom.childNodes[-1].childNodes)
  189.     dom.unlink()
  190.  
  191. def testUnlink():
  192.     dom = parse(tstfile)
  193.     dom.unlink()
  194.  
  195. def testElement():
  196.     dom = Document()
  197.     dom.appendChild(dom.createElement("abc"))
  198.     confirm(dom.documentElement)
  199.     dom.unlink()
  200.  
  201. def testAAA():
  202.     dom = parseString("<abc/>")
  203.     el = dom.documentElement
  204.     el.setAttribute("spam", "jam2")
  205.     confirm(el.toxml() == '<abc spam="jam2"/>', "testAAA")
  206.     a = el.getAttributeNode("spam")
  207.     confirm(a.ownerDocument is dom,
  208.             "setAttribute() sets ownerDocument")
  209.     confirm(a.ownerElement is dom.documentElement,
  210.             "setAttribute() sets ownerElement")
  211.     dom.unlink()
  212.  
  213. def testAAB():
  214.     dom = parseString("<abc/>")
  215.     el = dom.documentElement
  216.     el.setAttribute("spam", "jam")
  217.     el.setAttribute("spam", "jam2")
  218.     confirm(el.toxml() == '<abc spam="jam2"/>', "testAAB")
  219.     dom.unlink()
  220.  
  221. def testAddAttr():
  222.     dom = Document()
  223.     child = dom.appendChild(dom.createElement("abc"))
  224.  
  225.     child.setAttribute("def", "ghi")
  226.     confirm(child.getAttribute("def") == "ghi")
  227.     confirm(child.attributes["def"].value == "ghi")
  228.  
  229.     child.setAttribute("jkl", "mno")
  230.     confirm(child.getAttribute("jkl") == "mno")
  231.     confirm(child.attributes["jkl"].value == "mno")
  232.  
  233.     confirm(len(child.attributes) == 2)
  234.  
  235.     child.setAttribute("def", "newval")
  236.     confirm(child.getAttribute("def") == "newval")
  237.     confirm(child.attributes["def"].value == "newval")
  238.  
  239.     confirm(len(child.attributes) == 2)
  240.     dom.unlink()
  241.  
  242. def testDeleteAttr():
  243.     dom = Document()
  244.     child = dom.appendChild(dom.createElement("abc"))
  245.  
  246.     confirm(len(child.attributes) == 0)
  247.     child.setAttribute("def", "ghi")
  248.     confirm(len(child.attributes) == 1)
  249.     del child.attributes["def"]
  250.     confirm(len(child.attributes) == 0)
  251.     dom.unlink()
  252.  
  253. def testRemoveAttr():
  254.     dom = Document()
  255.     child = dom.appendChild(dom.createElement("abc"))
  256.  
  257.     child.setAttribute("def", "ghi")
  258.     confirm(len(child.attributes) == 1)
  259.     child.removeAttribute("def")
  260.     confirm(len(child.attributes) == 0)
  261.  
  262.     dom.unlink()
  263.  
  264. def testRemoveAttrNS():
  265.     dom = Document()
  266.     child = dom.appendChild(
  267.             dom.createElementNS("http://www.python.org", "python:abc"))
  268.     child.setAttributeNS("http://www.w3.org", "xmlns:python",
  269.                                             "http://www.python.org")
  270.     child.setAttributeNS("http://www.python.org", "python:abcattr", "foo")
  271.     confirm(len(child.attributes) == 2)
  272.     child.removeAttributeNS("http://www.python.org", "abcattr")
  273.     confirm(len(child.attributes) == 1)
  274.  
  275.     dom.unlink()
  276.  
  277. def testRemoveAttributeNode():
  278.     dom = Document()
  279.     child = dom.appendChild(dom.createElement("foo"))
  280.     child.setAttribute("spam", "jam")
  281.     confirm(len(child.attributes) == 1)
  282.     node = child.getAttributeNode("spam")
  283.     child.removeAttributeNode(node)
  284.     confirm(len(child.attributes) == 0)
  285.  
  286.     dom.unlink()
  287.  
  288. def testChangeAttr():
  289.     dom = parseString("<abc/>")
  290.     el = dom.documentElement
  291.     el.setAttribute("spam", "jam")
  292.     confirm(len(el.attributes) == 1)
  293.     el.setAttribute("spam", "bam")
  294.     confirm(len(el.attributes) == 1)
  295.     el.attributes["spam"] = "ham"
  296.     confirm(len(el.attributes) == 1)
  297.     el.setAttribute("spam2", "bam")
  298.     confirm(len(el.attributes) == 2)
  299.     el.attributes[ "spam2"] = "bam2"
  300.     confirm(len(el.attributes) == 2)
  301.     dom.unlink()
  302.  
  303. def testGetAttrList():
  304.     pass
  305.  
  306. def testGetAttrValues(): pass
  307.  
  308. def testGetAttrLength(): pass
  309.  
  310. def testGetAttribute(): pass
  311.  
  312. def testGetAttributeNS(): pass
  313.  
  314. def testGetAttributeNode(): pass
  315.  
  316. def testGetElementsByTagNameNS():
  317.     d="""<foo xmlns:minidom="http://pyxml.sf.net/minidom">
  318.     <minidom:myelem/>
  319.     </foo>"""
  320.     dom = parseString(d)
  321.     elem = dom.getElementsByTagNameNS("http://pyxml.sf.net/minidom","myelem")
  322.     confirm(len(elem) == 1)
  323.     dom.unlink()
  324.  
  325. def testGetEmptyNodeListFromElementsByTagNameNS(): pass
  326.  
  327. def testElementReprAndStr():
  328.     dom = Document()
  329.     el = dom.appendChild(dom.createElement("abc"))
  330.     string1 = repr(el)
  331.     string2 = str(el)
  332.     confirm(string1 == string2)
  333.     dom.unlink()
  334.  
  335. # commented out until Fredrick's fix is checked in
  336. def _testElementReprAndStrUnicode():
  337.     dom = Document()
  338.     el = dom.appendChild(dom.createElement(u"abc"))
  339.     string1 = repr(el)
  340.     string2 = str(el)
  341.     confirm(string1 == string2)
  342.     dom.unlink()
  343.  
  344. # commented out until Fredrick's fix is checked in
  345. def _testElementReprAndStrUnicodeNS():
  346.     dom = Document()
  347.     el = dom.appendChild(
  348.         dom.createElementNS(u"http://www.slashdot.org", u"slash:abc"))
  349.     string1 = repr(el)
  350.     string2 = str(el)
  351.     confirm(string1 == string2)
  352.     confirm(string1.find("slash:abc") != -1)
  353.     dom.unlink()
  354.  
  355. def testAttributeRepr():
  356.     dom = Document()
  357.     el = dom.appendChild(dom.createElement(u"abc"))
  358.     node = el.setAttribute("abc", "def")
  359.     confirm(str(node) == repr(node))
  360.     dom.unlink()
  361.  
  362. def testTextNodeRepr(): pass
  363.  
  364. def testWriteXML():
  365.     str = '<?xml version="1.0" ?>\n<a b="c"/>'
  366.     dom = parseString(str)
  367.     domstr = dom.toxml()
  368.     dom.unlink()
  369.     confirm(str == domstr)
  370.  
  371. def testProcessingInstruction(): pass
  372.  
  373. def testProcessingInstructionRepr(): pass
  374.  
  375. def testTextRepr(): pass
  376.  
  377. def testWriteText(): pass
  378.  
  379. def testDocumentElement(): pass
  380.  
  381. def testTooManyDocumentElements():
  382.     doc = parseString("<doc/>")
  383.     elem = doc.createElement("extra")
  384.     try:
  385.         doc.appendChild(elem)
  386.     except HierarchyRequestErr:
  387.         pass
  388.     else:
  389.         print "Failed to catch expected exception when" \
  390.               " adding extra document element."
  391.     elem.unlink()
  392.     doc.unlink()
  393.  
  394. def testCreateElementNS(): pass
  395.  
  396. def testCreateAttributeNS(): pass
  397.  
  398. def testParse(): pass
  399.  
  400. def testParseString(): pass
  401.  
  402. def testComment(): pass
  403.  
  404. def testAttrListItem(): pass
  405.  
  406. def testAttrListItems(): pass
  407.  
  408. def testAttrListItemNS(): pass
  409.  
  410. def testAttrListKeys(): pass
  411.  
  412. def testAttrListKeysNS(): pass
  413.  
  414. def testAttrListValues(): pass
  415.  
  416. def testAttrListLength(): pass
  417.  
  418. def testAttrList__getitem__(): pass
  419.  
  420. def testAttrList__setitem__(): pass
  421.  
  422. def testSetAttrValueandNodeValue(): pass
  423.  
  424. def testParseElement(): pass
  425.  
  426. def testParseAttributes(): pass
  427.  
  428. def testParseElementNamespaces(): pass
  429.  
  430. def testParseAttributeNamespaces(): pass
  431.  
  432. def testParseProcessingInstructions(): pass
  433.  
  434. def testChildNodes(): pass
  435.  
  436. def testFirstChild(): pass
  437.  
  438. def testHasChildNodes(): pass
  439.  
  440. def testCloneElementShallow():
  441.     dom, clone = _setupCloneElement(0)
  442.     confirm(len(clone.childNodes) == 0
  443.             and clone.childNodes.length == 0
  444.             and clone.parentNode is None
  445.             and clone.toxml() == '<doc attr="value"/>'
  446.             , "testCloneElementShallow")
  447.     dom.unlink()
  448.  
  449. def testCloneElementDeep():
  450.     dom, clone = _setupCloneElement(1)
  451.     confirm(len(clone.childNodes) == 1
  452.             and clone.childNodes.length == 1
  453.             and clone.parentNode is None
  454.             and clone.toxml() == '<doc attr="value"><foo/></doc>'
  455.             , "testCloneElementDeep")
  456.     dom.unlink()
  457.  
  458. def _setupCloneElement(deep):
  459.     dom = parseString("<doc attr='value'><foo/></doc>")
  460.     root = dom.documentElement
  461.     clone = root.cloneNode(deep)
  462.     _testCloneElementCopiesAttributes(
  463.         root, clone, "testCloneElement" + (deep and "Deep" or "Shallow"))
  464.     # mutilate the original so shared data is detected
  465.     root.tagName = root.nodeName = "MODIFIED"
  466.     root.setAttribute("attr", "NEW VALUE")
  467.     root.setAttribute("added", "VALUE")
  468.     return dom, clone
  469.  
  470. def _testCloneElementCopiesAttributes(e1, e2, test):
  471.     attrs1 = e1.attributes
  472.     attrs2 = e2.attributes
  473.     keys1 = attrs1.keys()
  474.     keys2 = attrs2.keys()
  475.     keys1.sort()
  476.     keys2.sort()
  477.     confirm(keys1 == keys2, "clone of element has same attribute keys")
  478.     for i in range(len(keys1)):
  479.         a1 = attrs1.item(i)
  480.         a2 = attrs2.item(i)
  481.         confirm(a1 is not a2
  482.                 and a1.value == a2.value
  483.                 and a1.nodeValue == a2.nodeValue
  484.                 and a1.namespaceURI == a2.namespaceURI
  485.                 and a1.localName == a2.localName
  486.                 , "clone of attribute node has proper attribute values")
  487.         confirm(a2.ownerElement is e2,
  488.                 "clone of attribute node correctly owned")
  489.  
  490.  
  491. def testCloneDocumentShallow(): pass
  492.  
  493. def testCloneDocumentDeep(): pass
  494.  
  495. def testCloneAttributeShallow(): pass
  496.  
  497. def testCloneAttributeDeep(): pass
  498.  
  499. def testClonePIShallow(): pass
  500.  
  501. def testClonePIDeep(): pass
  502.  
  503. def testNormalize():
  504.     doc = parseString("<doc/>")
  505.     root = doc.documentElement
  506.     root.appendChild(doc.createTextNode("first"))
  507.     root.appendChild(doc.createTextNode("second"))
  508.     confirm(len(root.childNodes) == 2
  509.             and root.childNodes.length == 2, "testNormalize -- preparation")
  510.     doc.normalize()
  511.     confirm(len(root.childNodes) == 1
  512.             and root.childNodes.length == 1
  513.             and root.firstChild is root.lastChild
  514.             and root.firstChild.data == "firstsecond"
  515.             , "testNormalize -- result")
  516.     doc.unlink()
  517.  
  518.     doc = parseString("<doc/>")
  519.     root = doc.documentElement
  520.     root.appendChild(doc.createTextNode(""))
  521.     doc.normalize()
  522.     confirm(len(root.childNodes) == 0
  523.             and root.childNodes.length == 0,
  524.             "testNormalize -- single empty node removed")
  525.     doc.unlink()
  526.  
  527. def testSiblings():
  528.     doc = parseString("<doc><?pi?>text?<elm/></doc>")
  529.     root = doc.documentElement
  530.     (pi, text, elm) = root.childNodes
  531.  
  532.     confirm(pi.nextSibling is text and
  533.             pi.previousSibling is None and
  534.             text.nextSibling is elm and
  535.             text.previousSibling is pi and
  536.             elm.nextSibling is None and
  537.             elm.previousSibling is text, "testSiblings")
  538.  
  539.     doc.unlink()
  540.  
  541. def testParents():
  542.     doc = parseString("<doc><elm1><elm2/><elm2><elm3/></elm2></elm1></doc>")
  543.     root = doc.documentElement
  544.     elm1 = root.childNodes[0]
  545.     (elm2a, elm2b) = elm1.childNodes
  546.     elm3 = elm2b.childNodes[0]
  547.  
  548.     confirm(root.parentNode is doc and
  549.             elm1.parentNode is root and
  550.             elm2a.parentNode is elm1 and
  551.             elm2b.parentNode is elm1 and
  552.             elm3.parentNode is elm2b, "testParents")
  553.  
  554.     doc.unlink()
  555.  
  556. def testNodeListItem():
  557.     doc = parseString("<doc><e/><e/></doc>")
  558.     children = doc.childNodes
  559.     docelem = children[0]
  560.     confirm(children[0] is children.item(0)
  561.             and children.item(1) is None
  562.             and docelem.childNodes.item(0) is docelem.childNodes[0]
  563.             and docelem.childNodes.item(1) is docelem.childNodes[1]
  564.             and docelem.childNodes.item(0).childNodes.item(0) is None,
  565.             "test NodeList.item()")
  566.     doc.unlink()
  567.  
  568. def testSAX2DOM():
  569.     from xml.dom import pulldom
  570.  
  571.     sax2dom = pulldom.SAX2DOM()
  572.     sax2dom.startDocument()
  573.     sax2dom.startElement("doc", {})
  574.     sax2dom.characters("text")
  575.     sax2dom.startElement("subelm", {})
  576.     sax2dom.characters("text")
  577.     sax2dom.endElement("subelm")
  578.     sax2dom.characters("text")
  579.     sax2dom.endElement("doc")
  580.     sax2dom.endDocument()
  581.  
  582.     doc = sax2dom.document
  583.     root = doc.documentElement
  584.     (text1, elm1, text2) = root.childNodes
  585.     text3 = elm1.childNodes[0]
  586.  
  587.     confirm(text1.previousSibling is None and
  588.             text1.nextSibling is elm1 and
  589.             elm1.previousSibling is text1 and
  590.             elm1.nextSibling is text2 and
  591.             text2.previousSibling is elm1 and
  592.             text2.nextSibling is None and
  593.             text3.previousSibling is None and
  594.             text3.nextSibling is None, "testSAX2DOM - siblings")
  595.  
  596.     confirm(root.parentNode is doc and
  597.             text1.parentNode is root and
  598.             elm1.parentNode is root and
  599.             text2.parentNode is root and
  600.             text3.parentNode is elm1, "testSAX2DOM - parents")
  601.  
  602.     doc.unlink()
  603.  
  604. # --- MAIN PROGRAM
  605.  
  606. names = globals().keys()
  607. names.sort()
  608.  
  609. failed = []
  610.  
  611. try:
  612.     Node.allnodes
  613. except AttributeError:
  614.     # We don't actually have the minidom from the standard library,
  615.     # but are picking up the PyXML version from site-packages.
  616.     def check_allnodes():
  617.         pass
  618. else:
  619.     def check_allnodes():
  620.         confirm(len(Node.allnodes) == 0,
  621.                 "assertion: len(Node.allnodes) == 0")
  622.         if len(Node.allnodes):
  623.             print "Garbage left over:"
  624.             if verbose:
  625.                 print Node.allnodes.items()[0:10]
  626.             else:
  627.                 # Don't print specific nodes if repeatable results
  628.                 # are needed
  629.                 print len(Node.allnodes)
  630.         Node.allnodes = {}
  631.  
  632. for name in names:
  633.     if name.startswith("test"):
  634.         func = globals()[name]
  635.         try:
  636.             func()
  637.             check_allnodes()
  638.         except:
  639.             failed.append(name)
  640.             print "Test Failed: ", name
  641.             sys.stdout.flush()
  642.             traceback.print_exception(*sys.exc_info())
  643.             print `sys.exc_info()[1]`
  644.             Node.allnodes = {}
  645.  
  646. if failed:
  647.     print "\n\n\n**** Check for failures in these tests:"
  648.     for name in failed:
  649.         print "  " + name
  650.